home *** CD-ROM | disk | FTP | other *** search
- // ----------------------------------------------------------------------------------------------------
- //
- // C O P Y R I G H T N O T I C E
- //
- // The code contained within this source file is copyright
- // N. A. Balharrie, 1995. It may not be reproduced, used,
- // or altered in any way without the above named copyright
- // holders written permission.
- //
- // ----------------------------------------------------------------------------------------------------
- // TODO Wish List
- //
- // - Files extracted with the get command to have the same name as the CDROM.
- // - Wildcards to be added to all file commands.
- // - Directory stack (ie. pushd and popd)
- // - cd should keep trying objects until it finds a match.
- // - Allow for intialisation file.
- // - Allow product information files to be viewed easily.
- // - Allow an index file to be attached, thus allowing a file to be found
- // via a whereis command.
- // - Multiple file extractions
- // - Recursive file extractions.
- // H Filename completion (rudimentary version available via wildcards)
- // - Modify last command.
- // - Command history buffer.
- // - Produce log file at users request.
- //
- // ----------------------------------------------------------------------------------------------------
-
- #include <stdio.h>
- #include <conio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <io.h>
-
- // ----------------------------------------------------------------------------------------------------
-
- #define FALSE (0)
- #define TRUE (1)
-
- // ----------------------------------------------------------------------------------------------------
-
- #pragma pack(1)
-
- // ----------------------------------------------------------------------------------------------------
-
- int file_number = 0;
- const int max_lines = 20;
- char* output_dir = "";
-
- // ----------------------------------------------------------------------------------------------------
- // ISO-9660 directory entry structure
-
- typedef struct dir_entry
- {
- unsigned char len_dr; // length of this directory entry
- unsigned char XAR_len; // XAR length in LBN's (logical blocks numbers)
- unsigned long loc_extentI; // LBN of data Intel format
- unsigned long loc_extentM; // LBN of data Molorola format
- unsigned long data_lenI; // length of file Intel format
- unsigned long data_lenM; // length of file Motorola format
- unsigned char record_time[7]; // date and time
- unsigned char file_flags_iso; // 8 flags
- unsigned char il_size; // interleave size
- unsigned char il_skip; // interleave skip factor
- unsigned short VSSNI; // volume set sequence number Intel
- unsigned short VSSNM; // volume set sequence number Motorola
- unsigned char len_fi; // length of name
- unsigned char file_id[256]; // variable length name upto 32 chars
- } dir_entry;
-
- // ----------------------------------------------------------------------------------------------------
- // Primary volume description
-
- typedef struct prim_vol_desc {
- unsigned char type;
- char id[5];
- unsigned char version;
- char pad1;
- char system_id[32];
- char volume_id[32];
- char pad2[8];
- unsigned long space_size_i;
- unsigned long space_size_m;
- char pad3[32];
- unsigned short set_size_i;
- unsigned short set_size_m;
- unsigned short sequence_i;
- unsigned short sequence_m;
- unsigned short block_size_i;
- unsigned short block_size_m;
- unsigned long path_size_i;
- unsigned long path_size_m;
- unsigned long i_table;
- unsigned long opt_i_table;
- unsigned long m_table;
- unsigned long opt_m_table;
- dir_entry root;
- char volume_set_id[128];
- char publisher_id[128];
- char data_preparer[128];
- char application_id[128];
- char copyright[37];
- char abstract_file_id[37];
- char bibliographic_id[37];
- char vol_creation[17];
- char vol_modification[17];
- char vol_expiration[17];
- char vol_effective[17];
- unsigned char file_structure_version;
- char pad4;
- char application_use[512];
- char reserved[653];
- } prim_vol_desc;
-
- // ----------------------------------------------------------------------------------------------------
-
- const int buffer_length = 2048;
-
- class CDROM {
- protected:
- void make_string( char _far* string_in, int length );
-
- public:
- void read_sector( unsigned long sector, unsigned char _far* buffer );
- void read_voldesc( unsigned char _far* buffer );
- void motorola_to_intel( unsigned long _far* motorola, unsigned long _far* intel );
- };
-
- // ----------------------------------------------------------------------------------------------------
-
- void CDROM::motorola_to_intel( unsigned long _far* motorola, unsigned long _far* intel )
- {
- unsigned char old_val[ 4 ];
- unsigned char new_val[ 4 ];
-
- memcpy( (char*)old_val, (char*)motorola, 4 );
- new_val[ 0 ] = old_val[ 3 ];
- new_val[ 1 ] = old_val[ 2 ];
- new_val[ 2 ] = old_val[ 1 ];
- new_val[ 3 ] = old_val[ 0 ];
- memcpy( (char*)intel, (char*)new_val, 4 );
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void CDROM::read_sector( unsigned long sector, unsigned char _far* buffer )
- {
- short hi_sector, lo_sector;
- short hi_buffer, lo_buffer;
-
- lo_sector = (short)(sector & 0xffff);
- hi_sector = (short)((sector >> 16) & 0xffff);
-
- lo_buffer = (short)((unsigned long)buffer & 0xffff);
- hi_buffer = (short)(((unsigned long)buffer >> 16) & 0xffff);
-
- _asm {
- mov ax,0x1500
- int 0x2f
-
- mov ax,0x1508
- mov dx,0x0001
- mov si,hi_sector
- mov di,lo_sector
- mov bx, hi_buffer
- mov es,bx
- mov bx, lo_buffer
- int 0x2f
- };
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void CDROM::read_voldesc( unsigned char _far* buffer )
- {
- short hi_buffer, lo_buffer;
-
- lo_buffer = (short)((unsigned long)buffer & 0xffff);
- hi_buffer = (short)(((unsigned long)buffer >> 16) & 0xffff);
-
- _asm {
- mov ax,0x1500
- int 0x2f
-
- mov ax,0x1505
- mov dx,0x0001
- mov bx, hi_buffer
- mov es,bx
- mov bx, lo_buffer
- int 0x2f
- };
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void CDROM::make_string( char _far* string_in, int length )
- {
- int pos;
- for ( pos = length; (pos > -1) && (string_in[ pos ] == ' '); pos --)
- string_in[ pos ] = '\0';
-
- for ( pos = 0; string_in[ pos ] != '\0'; pos++ )
- if (string_in[ pos ] == ';')
- string_in[ pos ] = '\0';
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- class volume : public CDROM {
- unsigned char _far* buffer;
- prim_vol_desc _far* vol_desc;
-
- public:
- volume();
- ~volume();
-
- void show( void );
-
- unsigned long root_sector( void ) { return (vol_desc->root.loc_extentI); }
- unsigned long root_length( void ) { return (vol_desc->root.data_lenI); }
- int type( void ) { return vol_desc->type; }
-
- const char _far* get_std_ident( void ) { return &vol_desc->id[ 0 ]; }
- const char _far* system_id( void ) { return &vol_desc->system_id[ 0 ]; }
- const char _far* volume_id( void ) { return &vol_desc->volume_id[ 0 ]; }
- };
-
- // ----------------------------------------------------------------------------------------------------
-
- volume::volume()
- {
- buffer = new unsigned char[ buffer_length ];
- vol_desc = (prim_vol_desc _far*)buffer;
- read_voldesc( buffer );
- // read_sector( 16, buffer );
-
- // motorola_to_intel( &vol_desc->root.loc_extentM, &vol_desc->root.loc_extentI );
- // motorola_to_intel( &vol_desc->root.data_lenM, &vol_desc->root.data_lenI );
-
- make_string( &vol_desc->system_id[ 0 ], 32 );
- make_string( &vol_desc->volume_id[ 0 ], 32 );
- make_string( &vol_desc->volume_set_id[ 0 ], 128 );
- make_string( &vol_desc->publisher_id[ 0 ], 128 );
- make_string( &vol_desc->data_preparer[ 0 ], 128 );
- make_string( &vol_desc->application_id[ 0 ], 128 );
- make_string( &vol_desc->copyright[ 0 ], 37 );
- make_string( &vol_desc->abstract_file_id[ 0 ], 37 );
- make_string( &vol_desc->bibliographic_id[ 0 ], 37 );
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- volume::~volume()
- {
- delete[] buffer;
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void volume::show( void )
- {
- printf( "\n");
- printf( "Volume Descriptor Type: %d\n", (int) vol_desc->type );
- printf( "Standard Identifier: %s\n", (char *)vol_desc->id );
- printf( "Volume Descriptor Version: %d\n", (int) vol_desc->version );
- printf( "System Identifier: %s\n", (char *)vol_desc->system_id );
- printf( "Volume Identifier: %s\n", (char *)vol_desc->volume_id );
- printf( "Volume Space Size: %d\n", vol_desc->space_size_i );
- printf( "Volume Set Size: %d\n", vol_desc->set_size_i );
- printf( "Volume Sequence Number: %d\n", vol_desc->sequence_i );
- printf( "Logical Block Size: %d\n", vol_desc->block_size_i );
- printf( "Path Table Size: %d\n", vol_desc->path_size_i );
- printf( "Location of Occ of M Path Table: %d\n", vol_desc->i_table );
- printf( "Location of Occ of Opt M Path T: %d\n", vol_desc->opt_i_table );
- printf( "Volume Set Identifier: %s\n", (char *)vol_desc->volume_set_id );
- printf( "Publisher Identifier: %s\n", (char *)vol_desc->publisher_id );
- printf( "Data Preparer Identifier: %s\n", (char *)vol_desc->data_preparer );
- printf( "Application Identifier: %s\n", (char *)vol_desc->application_id );
- printf( "Copyright File Identifier: %s\n", (char *)vol_desc->copyright );
- printf( "Abstract File Identifier: %s\n", (char *)vol_desc->abstract_file_id );
- printf( "Bibliographic File Identifier: %s\n", (char *)vol_desc->bibliographic_id );
- printf( "File Structure Version: %d\n", (int) vol_desc->file_structure_version );
- // printf( "\nROOT DIRECTORY RECORD:\n";
- }
-
- // ----------------------------------------------------------------------------------------------------
- const int SHORT = 0;
- const int LONG = 1;
- const int NORMAL = 2;
-
- class directory : public CDROM {
- private:
- unsigned long start_sector;
- unsigned long current_sector;
- unsigned long length;
- unsigned long overall_pos;
- short buf_pos;
-
- char* name;
-
- unsigned char _far* dir_buffer;
- unsigned char file_buffer[ buffer_length ];
- short dir_pos;
-
- dir_entry file;
-
- void to_start_dir_entry( void );
- int get_next_dir_entry( void );
-
- char* wild_card;
- int wild_card_cmp( char* string, char* wild );
-
- void show_flags( void );
-
- int is_directory( void ) { return (file.file_flags_iso & 0x02); }
- int is_file( void ) { return !(file.file_flags_iso & 0xff); }
-
- void show_long_entry( void );
- void show_short_entry( void );
- void show_normal( void );
-
- int display_file( void );
- int grab_file( int interactive = 0 );
-
- public:
- directory( char* old_name, char* dir_name, unsigned long dir_sector, unsigned long dir_length );
- directory( volume& CDROM_vol );
- directory::~directory();
-
- dir_entry* find_first( char* search );
- dir_entry* find_next( void );
-
- char* get_name( void ) { return name; }
-
- void show_directory( char* search, int long_dir = NORMAL );
-
- directory* change_dir( char* dir_name );
-
- void show_file( char* filename );
-
- void get_file( char* filename, int interactive );
- };
-
- // ----------------------------------------------------------------------------------------------------
-
- volume primary_VTOC;
-
- directory* root;
- directory* current_dir;
-
- // ----------------------------------------------------------------------------------------------------
-
- directory::directory( char* old_name, char* dir_name,
- unsigned long dir_sector, unsigned long dir_length )
- {
- current_sector = start_sector = dir_sector;
- length = dir_length;
- name = new char[ strlen( old_name ) + strlen( dir_name ) + 3 ];
- wild_card = NULL;
- name[ 0 ] = '\0';
-
- if (!strcmp( dir_name, "." ))
- strcpy( name, old_name );
- else if (!strcmp( dir_name, ".."))
- {
- int found = 0;
- strcpy( name, old_name );
- for (int i = strlen( name ); (i > 0) && !found; i--)
- {
- if (name[ i ] == '\\')
- found = 1;
- name[ i ] = '\0';
- }
- }
- else if (!strcmp( old_name, "\\" ))
- {
- strcpy( name, "\\" );
- strcat( name, dir_name );
- }
- else
- {
- strcpy( name, old_name );
- strcat( name, "\\" );
- strcat( name, dir_name );
- }
-
- dir_buffer = new unsigned char[ 2048 ];
-
- to_start_dir_entry();
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- directory::directory( volume& CDROM_vol )
- {
- current_sector = start_sector = CDROM_vol.root_sector();
- length = CDROM_vol.root_length();
- wild_card = NULL;
- name = new char[ 3 ];
- strcpy( name , "\\" );
-
- dir_buffer = new unsigned char[ 2048 ];
-
- to_start_dir_entry();
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- directory::~directory()
- {
- if (name)
- delete[] name;
-
- if (wild_card)
- delete[] wild_card;
-
- delete[] dir_buffer;
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- directory* directory::change_dir( char* dir_name )
- {
- char* name;
- char* rest;
- int found = 0;
-
- name = dir_name;
- rest = NULL;
-
- for (char* pos = name; !found & (*pos !='\0'); pos++)
- if (*pos =='\\')
- {
- rest = pos + 1;
- *pos = '\0';
- found = 1;
- }
- if (strlen( name ) == 0)
- {
- directory* new_dir;
- new_dir = new directory( primary_VTOC );
- delete current_dir;
- current_dir = new_dir;
- }
- else if (find_first( name ))
- {
- directory* new_dir;
- new_dir = new directory( current_dir->name, (char*)file.file_id, file.loc_extentI, file.data_lenI );
- delete current_dir;
- current_dir = new_dir;
- }
- else
- return NULL;
-
- if (rest != NULL)
- return current_dir->change_dir( rest );
- else
- return current_dir;
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- int directory::display_file( void )
- {
- char ans;
- if (is_file())
- {
- printf( "Do you wish to view [%s] (Y/N/A) ?\n", file.file_id );
-
- ans = _getch();
- if ((ans == 'y') || (ans == 'Y'))
- {
- unsigned long sector = file.loc_extentI;
- unsigned long display_len = file.data_lenI;
- int sector_pos = 0;
- int lines = 0;
-
- read_sector( sector++, (unsigned char _far*)file_buffer );
- while (display_len > 0)
- {
- display_len--;
- printf( "%c", file_buffer[ sector_pos ] );
-
- if (file_buffer[ sector_pos ] == '\n')
- lines++;
-
- if (lines == max_lines)
- {
- lines = 0;
- printf( "Paused - Return to continue, Q to quit, A to abort all\n" );
- ans = _getch();
- if ((ans == 'q') || (ans == 'Q'))
- return 0;
- if ((ans == 'a') || (ans == 'A'))
- return 0;
- printf("\r");
- }
-
- sector_pos++;
- if (sector_pos == 2048)
- {
- read_sector( sector++, (unsigned char _far*)file_buffer );
- sector_pos = 0;
- }
- }
- return 0;
- }
- else if ((ans == 'n') || (ans == 'N'))
- return 0;
- else
- return 1;
- }
- else
- return 0;
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void directory::show_file( char* filename )
- {
- int aborted;
-
- if (find_first( filename ))
- aborted = display_file();
-
- while (find_next() && !aborted)
- aborted = display_file();
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- int directory::grab_file( int interactive )
- {
- FILE* out_file;
- int length;
- char new_filename[ 128 ];
- char ans;
-
- if (interactive && is_file())
- {
- printf( "Do you wish to get [%s] (Y/N/A) ?\n", file.file_id );
- ans = _getch();
-
- if ((ans == 'A') || (ans == 'a'))
- return 1;
- }
-
- if ((!interactive || (ans == 'y') || (ans == 'Y')) && is_file())
- {
- strcpy( new_filename, output_dir );
- if (length = strlen( new_filename ))
- {
- if (new_filename[ length - 1 ] != '\\')
- strcat( new_filename, "\\" );
- }
- strcat( (char*)new_filename, (char*)file.file_id );
-
- if ((out_file = fopen( new_filename, "wb" )) == NULL)
- {
- strcpy( new_filename, output_dir );
- if (length = strlen( new_filename ))
- {
- if (new_filename[ length - 1 ] != '\\')
- strcat( new_filename, "\\" );
- }
- char temp_str[ 20 ];
- sprintf( temp_str, "%08x.cdr", file_number++ );
- strcat( (char*)new_filename, temp_str );
- out_file = fopen( new_filename, "wb" );
- }
-
- if (out_file != NULL)
- {
- unsigned long file_length = file.data_lenI;
- unsigned long sector = file.loc_extentI;
-
- printf( "Writing file %s to %s %lu bytes\n", file.file_id, new_filename, file_length );
-
- while (file_length)
- {
- int block_size;
-
- if (file_length >= 2048 )
- block_size = 2048;
- else
- block_size = file_length;
-
- read_sector( sector++, file_buffer );
- fwrite( file_buffer, 1, (size_t)block_size, out_file );
- file_length -= block_size;
- }
- fclose( out_file );
- }
- else
- printf( "Failed to write %s\n", new_filename );
- }
-
- return 0;
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void directory::get_file( char* filename, int interactive )
- {
- int aborted;
-
- if (find_first( filename ))
- aborted = grab_file( interactive );
-
- while (find_next() && !aborted)
- aborted = grab_file( interactive );
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void directory::show_long_entry( void )
- {
- printf( "File Identifier: %s\n", file.file_id );
- printf( "Data Length: %lu\n", file.data_lenI );
- printf( "File Identifier Length: %d\n", (int)file.len_fi );
- printf( "Extended Attr Record Length: %u\n", (int) file.XAR_len );
- printf( "Location of Extent: %lu\n", file.loc_extentI );
- printf( "Recording Date and Time: %02d.%02d.19%02d %02d:%02d:%02d\n",
- (int) file.record_time[ 2 ], (int) file.record_time[ 1 ], (int) file.record_time[ 0 ],
- (int) file.record_time[ 3 ], (int) file.record_time[ 4 ], (int) file.record_time[ 5 ] );
- printf( "Flags: (%d ", (int) file.file_flags_iso );
-
- show_flags();
-
- printf( ")\n\n" );
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void directory::show_short_entry( void )
- {
- show_flags();
-
- printf( " %12lu ", file.data_lenI );
- printf( "%02d.%02d.19%02d %02d:%02d:%02d ",
- (int) file.record_time[ 2 ], (int) file.record_time[ 1 ], (int) file.record_time[ 0 ],
- (int) file.record_time[ 3 ], (int) file.record_time[ 4 ], (int) file.record_time[ 5 ] );
- printf( " %s\n" , file.file_id );
- }
-
-
- // ----------------------------------------------------------------------------------------------------
-
- void directory::show_normal( void )
- {
- if (is_file())
- printf( "%-32s ", file.file_id );
- else
- printf( "%%%-32s ", file.file_id );
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void directory::show_flags( void )
- {
- if (file.file_flags_iso == 0)
- printf( "file " );
-
- if (file.file_flags_iso & 1)
- printf( "existence " );
-
- if (file.file_flags_iso & 2)
- printf( "dir " );
-
- if (file.file_flags_iso & 4)
- printf( "associated " );
-
- if (file.file_flags_iso & 8)
- printf( "record " );
-
- if (file.file_flags_iso & 16)
- printf( "protection " );
-
- if (file.file_flags_iso & 128)
- printf( "multi-extent " );
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void directory::show_directory( char* search, int long_dir )
- {
- int finished = 0;
- int lines = 0;
- int column = 0;
- char ans;
-
- if (find_first( search ))
- {
- if (long_dir == LONG)
- {
- show_long_entry();
- lines = 1;
- }
- else if (long_dir == SHORT)
- {
- show_short_entry();
- lines = 1;
- }
- else
- {
- show_normal();
- column = 1;
- lines = 0;
- }
-
- while (find_next() && !finished)
- {
- if (long_dir == LONG)
- {
- show_long_entry();
- lines++;
- }
- else if (long_dir == SHORT)
- {
- show_short_entry();
- lines++;
- }
- else
- {
- show_normal();
- column++;
-
- if (column >= 2)
- {
- column = 0;
- lines++;
- printf( "\n" );
- }
- }
-
- if (lines == max_lines)
- {
- lines = 0;
- printf( "Paused - Return to continue, Q to quit\n" );
- ans = _getch();
- if ((ans == 'q') || (ans == 'Q'))
- finished = 1;
- printf("\r");
- }
- }
-
- if (long_dir == NORMAL)
- if (column)
- printf("\n");
- }
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void directory::to_start_dir_entry( void )
- {
- buf_pos = 0;
- overall_pos = 0;
- current_sector = start_sector;
- read_sector( start_sector, dir_buffer );
- }
-
- // ----------------------------------------------------------------------------------------------------
- // Gets the next directory entry in the list, and sets file to point to it.
- // Returns a 1 if another entry was found otherwise it returns a 0
-
- int directory::get_next_dir_entry( void )
- {
- if (overall_pos < length)
- {
- if (buf_pos >= buffer_length)
- {
- buf_pos = 0;
- current_sector++;
- read_sector( current_sector, dir_buffer );
- }
-
- memcpy( &file, (dir_entry *)&dir_buffer[ buf_pos ], sizeof(dir_entry) );
- file.file_id[ file.len_fi ] = '\0';
- make_string( (char *)file.file_id, file.len_fi );
-
- if (file.file_id[ 0 ] == 0)
- {
- strcpy( (char *)file.file_id, "." );
- file.len_fi = 1;
- if ((file.loc_extentI != start_sector) && (file.len_dr))
- return 0;
- }
- else if (file.file_id[ 0 ] == 1)
- {
- strcpy( (char *)file.file_id, ".." );
- file.len_fi = 2;
- if (file.len_dr == 0)
- file.len_dr = 34;
- }
-
- buf_pos += file.len_dr;
- overall_pos += file.len_dr;
-
- // if (file.loc_extentI == 0)
- // {
- // buf_pos = 2048;
- // return get_next_dir_entry();
- // }
- // else
- if (file.len_dr == 0)
- {
- if (file.loc_extentI == start_sector)
- return 0;
- else
- {
- buf_pos = 2048;
- return get_next_dir_entry();
- }
- }
- else
- return 1;
- }
- else
- return 0;
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- dir_entry* directory::find_first( char* search_name )
- {
- if (wild_card)
- delete[] wild_card;
-
- wild_card = new char[ strlen( search_name ) + 1 ];
- strcpy( wild_card, search_name );
- to_start_dir_entry();
- return find_next();
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- dir_entry* directory::find_next( void )
- {
- int found = 0;
- int no_more = 0;
-
- while (!found && !no_more)
- {
- no_more = !get_next_dir_entry();
- found = wild_card_cmp( (char *)file.file_id, wild_card );
- }
-
- if (no_more)
- return NULL;
- else
- return &file;
- }
-
- // ----------------------------------------------------------------------------------------------------
- // Someday I will have to re-write this!
-
- int directory::wild_card_cmp( char* string, char* wild )
- {
- int match = TRUE;
- int finished = FALSE;
- char *str_pos = string;
- char *wild_pos = wild;
-
- if ((*str_pos != '\0') || (*wild_pos != '\0'))
- {
- do {
- switch (*wild_pos)
- {
- case '*':
- while ((*wild_pos != '\0') && ((*wild_pos == '?') || (*wild_pos == '*')))
- wild_pos++;
-
- if (*wild_pos != '\0')
- {
- do {
- if (!match)
- str_pos++;
-
- while ((*str_pos != '\0') && (tolower(*str_pos) != tolower(*wild_pos)))
- str_pos++;
-
- match = wild_card_cmp( str_pos, wild_pos );
-
- } while (!match && (*str_pos != '\0'));
-
- finished = match;
- }
- else
- finished = TRUE;
- break;
-
- case '?':
- str_pos++;
- wild_pos++;
- break;
-
- default:
- if (tolower( *str_pos ) == tolower( *wild_pos ))
- {
- str_pos++;
- wild_pos++;
- }
- else
- match = FALSE;
- break;
- }
- } while ((*str_pos != '\0') && (*wild_pos != '\0') && match && !finished);
-
- if ((*str_pos == '\0') && (*wild_pos !='\0'))
- while ((*wild_pos != '\0') && (*wild_pos == '*'))
- wild_pos++;
-
- if (!finished && ((*wild_pos != '\0') || (*str_pos != '\0')))
- match = FALSE;
- }
- else
- match = FALSE;
-
- return match;
- }
-
- /* ----------------------------------------------------------------------- */
-
- void show_copyright( void )
- {
- puts("\nGo Fishing, Version 1.1");
- puts(" AMIGA CDROM handler for MS-DOS");
- puts(" (c) 1995 N. A. Balharrie\n");
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- int command_line ( char *cmd_line )
- {
- char command[ 256 ];
- char parameter[ 256 ];
-
- int finished = FALSE;
-
- if (strlen(cmd_line))
- {
- command[ 0 ] = '\0';
- parameter[ 0 ] = '\0';
-
- sscanf( cmd_line, "%s %s", command, parameter );
-
- if ((!strcmp("quit", command )) || (!strcmp("lo", command )))
- finished = TRUE;
-
- // else if (!strcmp( "r", command ))
- // list_rec( &curr_dir );
-
- else if (!strcmp( "voldesc", command))
- primary_VTOC.show();
-
- else if (!strcmp( "ls", command ))
- if (parameter[ 0 ] == '\0')
- current_dir->show_directory( "*", NORMAL );
- else
- current_dir->show_directory( parameter, NORMAL );
-
- else if (!strcmp( "ex", command ))
- current_dir->show_directory( parameter, LONG );
-
- else if (!strcmp( "ll", command ))
- if (parameter[ 0 ] == '\0')
- current_dir->show_directory( "*", SHORT );
- else
- current_dir->show_directory( parameter, SHORT );
-
- else if (!strcmp( "cd", command ))
- {
- if (current_dir->change_dir( parameter ) == NULL)
- printf( "No such directory\n" );
- }
-
- else if (!strcmp( "pod", command ))
- printf("%s\n", output_dir );
-
- else if (!strcmp( "cod", command ))
- {
- delete[] output_dir;
- output_dir = new char[ strlen( parameter ) + 1 ];
- strcpy( output_dir, parameter );
- }
-
- else if (!strcmp( "more", command) || !strcmp( "m", command))
- current_dir->show_file( parameter );
-
- else if (!strcmp( "get", command ))
- current_dir->get_file( parameter, 0 );
-
- else if (!strcmp( "iget", command ))
- current_dir->get_file( parameter, 1 );
-
- // else if (!strcmp( "exec", command ))
- // exec_cmd( cmd_line );
-
- else if (!strcmp( "?", command ) || !strcmp( "help", command ))
- {
- show_copyright();
- puts( "Available commands\n" );
- puts( "quit - Quit the program" );
- puts( "voldesc - Display the CDROM descriptor");
- puts( "ls - List directory" );
- puts( "ll - Detailed directory list" );
- puts( "cd dir - Change to the `dir' directory" );
- puts( "cod dir - Change the current output directory to be `dir'" );
- puts( " (must include the final /, ie. /etc/ )" );
- puts( "pod - Display the current output directory" );
- puts( "get file - Get the specified file and place it in the 'cod'" );
- puts( "iget file - Interactively get the specified file and place it in the 'cod'" );
- puts( "more file - Display `file' on the terminal");
- puts( "m file - Shorthand for more" );
- puts( "exec file - Execut the script file `file'" );
- puts( "" );
- }
- else
- printf("%s is not recognised as a command.\n", command );
- }
- return finished;
- }
-
- // ----------------------------------------------------------------------------------------------------
-
- void main( void )
- {
- char cmd_line[ 256 ];
-
- root = new directory( primary_VTOC );
- current_dir = root;
-
- output_dir = new char[ 2 ];
- output_dir[ 0 ] = '\\';
- output_dir[ 1 ] = '\0';
-
- show_copyright();
-
- // exec_script( "fish-init", 0 );
- puts( "Type help or ? for a list of the commands\n" );
-
- do {
- printf("%s %% ", current_dir->get_name() );
- gets( cmd_line );
- } while ( !command_line( cmd_line ) );
-
- delete root;
- delete[] output_dir;
- }
-